package com.xbongbong.saas.enums.dictionary;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author: 汪腾伟
 * @date: 2020/7/29
 * @desrcption: 回款计划枚举
 * @version:1.0
 */
@Getter
public enum PaymentTaskStatusEnum {

    // 回款计划 状态
    NO_FINISH("1","noFinish", "enum.paymentTaskStatus.alias.no_finish"),
    FINISH("2","finish", "enum.paymentTaskStatus.alias.finish"),
    UNKNOW("404","unkonw", "enum.paymentTaskStatus.alias.unknow")
    ;
    private String code;
    private String attr;
    private String alias;

    PaymentTaskStatusEnum(String code, String attr, String alias) {
        this.code = code;
        this.attr = attr;
        this.alias = alias;
    }

    public static PaymentTaskStatusEnum getByCode(String code){
        for (PaymentTaskStatusEnum statusEnum : values()){
            if (Objects.equals(statusEnum.code,code)){
                return statusEnum;
            }
        }
        return UNKNOW;
    }

    public static List<PaymentTaskStatusEnum> getList(){
        List<PaymentTaskStatusEnum> enumList = new ArrayList<>();
        for (PaymentTaskStatusEnum statusEnum : values()){
            if (Objects.equals(statusEnum,UNKNOW)){
                continue;
            }
            enumList.add(statusEnum);
        }
        return enumList;
    }

    public static PaymentTaskStatusEnum getByAlias(String alias){
        for (PaymentTaskStatusEnum statusEnum : values()){
            if (Objects.equals(statusEnum.getAlias(), alias)){
                return statusEnum;
            }
        }
        return null;
    }

    public String getAlias() {
        return I18nMessageUtil.getMessage(alias);
    }

}
